#ifndef _BCOS_TERMINAL_H_
#define _BCOS_TERMINAL_H_

#include "bcos_pcb.h"
#include "slist.h"
#include <stdio.h>

typedef struct
{
	/* 链表头 */
	slist_t list;
	/* 命令名 */
	char     *name;
	/* 命令处理回调函数 */
	void (*handler)(int argc, char **argv);
}bcos_cmd_t;

typedef struct
{
	 FILE 		*file;
	 int 		mem_offset;
	 void 		*exe_addr;
	 uint32_t 	size;
	 void 		*r9;
}bcos_app_t;

typedef struct 
{
	/* list节点 */
	slist_t 	list;
	/* APP ID */
	uint8_t		aid;
	/* APP运行结构指针 */
	bcos_app_t	app;
	/* R9中保存的是APP全局变量的基地址 */
	void		*app_r9;
	/* APP退出处理接口 */
	void (*exit)(void);
}bcos_app_manage_t;

#define BCOS_TERMINAL_CMD_INIT(name, cmd_name, handler) \
{\
	SLIST_HEAD_INIT(name.list), \
	cmd_name,					\
	handler,					\
}

#define OPCODE_START_MODRECV	0x66
#define OPCODE_QUIT_MODRECV		0x10
#define OPCODE_APPEND_FILE		0x12
#define OPCODE_SET_FILENAME		0x14

extern bcos_tasklet_t bcos_terminal_tasklet;
extern slist_t app_manage_list;

void bcos_terminal_init(void);

void bcos_terminal_cmd_register(bcos_cmd_t *cmd);
void bcos_terminal_cmd_unregister(bcos_cmd_t *cmd);

int bcos_install_app_from_file(char *path, char *name);
int bcos_app_run(char *path);
int bcos_app_exit(uint8_t aid);

#endif
